home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 2 / Meeting Pearls Vol. II (1995)(GTI - Schatztruhe)[!].iso / Pearls / dev / GUI / Triton / Programmer / Source / triton_llib.c < prev   
C/C++ Source or Header  |  1994-07-14  |  7KB  |  224 lines

  1. /*
  2.  *  Triton - The object oriented GUI creation system for the Amiga
  3.  *  Written by Stefan Zeiger in 1993-1994
  4.  *
  5.  *  (c) 1993-1994 by Stefan Zeiger
  6.  *  You are hereby allowed to use this source or parts
  7.  *  of it for creating programs for AmigaOS which use the
  8.  *  Triton GUI creation system. All other rights reserved.
  9.  *
  10.  */
  11.  
  12.  
  13. #define TR_NOMACROS
  14. #define TR_NOSUPPORT
  15.  
  16. #include <dos.h>
  17. #include <utility/hooks.h>
  18. #include <clib/exec_protos.h>
  19. #include <pragmas/exec_pragmas.h>
  20. #include <libraries/triton.h>
  21. #include <proto/dos.h>
  22. #include <proto/intuition.h>
  23. #include <proto/graphics.h>
  24. #include <proto/triton.h>
  25. #include <clib/alib_protos.h>
  26. #include <ctype.h>
  27.  
  28.  
  29. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  30. //////////////////////////////////////////////////////////////////////////////////////// Support functions //
  31. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  32.  
  33. struct Library *TritonBase;
  34. struct TR_App *__Triton_Support_App;
  35.  
  36.  
  37. /****** triton.lib/TR_OpenTriton ******
  38. *
  39. *   NAME    
  40. *    TR_OpenTriton -- Opens Triton ready to use.
  41. *
  42. *   SYNOPSIS
  43. *    success = TR_OpenTriton(version, tag1,...)
  44. *    D0
  45. *
  46. *    BOOL TR_OpenTriton(ULONG, ULONG,...);
  47. *
  48. *   FUNCTION
  49. *    Opens triton.library with the specified minimum
  50. *    version and creates an application.
  51. *    The supplied tags are passed as a taglist to
  52. *    TR_CreateApp().
  53. *
  54. *   RESULT
  55. *    success - Was everything opened successful?
  56. *
  57. *   SEE ALSO
  58. *    TR_CloseTriton(), TR_CreateApp()
  59. *
  60. ******/
  61.  
  62. BOOL __stdargs TR_OpenTriton(ULONG version, ULONG taglist,...)
  63. {
  64.   if(!(TritonBase=OpenLibrary(TRITONNAME,version))) return FALSE;
  65.   if(!(__Triton_Support_App=TR_CreateApp((struct TagItem *)&taglist))) return FALSE;
  66.   return TRUE;
  67. }
  68.  
  69.  
  70. /****** triton.lib/TR_CloseTriton ******
  71. *
  72. *   NAME    
  73. *    TR_CloseTriton -- Closes Triton easily.
  74. *
  75. *   SYNOPSIS
  76. *    TR_CloseTriton()
  77. *
  78. *    VOID TR_CloseTriton(VOID);
  79. *
  80. *   FUNCTION
  81. *    Closes the application created by OpenTriton()
  82. *    and closes triton.library.
  83. *
  84. *   SEE ALSO
  85. *    TR_OpenTriton()
  86. *
  87. ******/
  88.  
  89. VOID __regargs TR_CloseTriton(VOID)
  90. {
  91.   if(__Triton_Support_App)
  92.   {
  93.     TR_DeleteApp(__Triton_Support_App);
  94.     __Triton_Support_App=NULL;
  95.   }
  96.   if(TritonBase)
  97.   {
  98.     CloseLibrary(TritonBase);
  99.     TritonBase=NULL;
  100.   }
  101. }
  102.  
  103.  
  104. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  105. ///////////////////////////////////////////////////////////////////////////////////// Stack argument stubs //
  106. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  107.  
  108. struct TR_App * __stdargs TR_CreateAppTags(ULONG taglist,...)
  109.   { return TR_CreateApp((struct TagItem *)&taglist); }
  110.  
  111. struct TR_Project * __stdargs TR_OpenProjectTags(struct TR_App *app, ULONG taglist,...)
  112.   { return TR_OpenProject(app, (struct TagItem *)&taglist); }
  113.  
  114. ULONG TR_EasyRequestTags(struct TR_App *app, STRPTR bodyfmt, STRPTR gadfmt, ULONG taglist,...)
  115.   { return TR_EasyRequest(app, bodyfmt, gadfmt, (struct TagItem *)&taglist); }
  116.  
  117. ULONG TR_AutoRequestTags(struct TR_App *app, struct TR_Project *lockproject, ULONG taglist,...)
  118.   { return TR_AutoRequest(app, lockproject, (struct TagItem *)&taglist); }
  119.  
  120.  
  121. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  122. ////////////////////////////////////////////////////////////////////////////// BOOPSI image class 'TRLOGO' //
  123. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  124.  
  125. struct IClass *TRIM_trLogo;
  126. ULONG    __regargs TRIM_trLogo_DrawBoopsiImage(struct Image *Image, struct impDraw *DrawMsg);
  127. ULONG    __asm TRIM_trLogo_DispatchBoopsiImage(register __a0 struct IClass *Class, register __a2 Object *Object, register __a1 Msg ObjMsg);
  128.  
  129.  
  130. #define ARROWLENGTH 4
  131. #define LANCELENGTH 2
  132. #define CURVELENGTH 15
  133.  
  134.  
  135. void __stdargs TR_ScaledPolyDraw(struct RastPort *rport, UWORD len, WORD *array, ULONG orgwid, ULONG orghei, ULONG newwid, ULONG newhei, ULONG left, ULONG top)
  136. {
  137.   UWORD i;
  138.  
  139.   for(i=0;i<len;i++)
  140.   {
  141.     array[i*2]=((array[i*2]*newwid)/orgwid)+left;
  142.     array[(i*2)+1]=((array[(i*2)+1]*newhei)/orghei)+top;
  143.   }
  144.   Move(rport, array[0], array[1]);
  145.   PolyDraw(rport, len-1, &array[2]);
  146. }
  147.  
  148.  
  149. ULONG    __regargs TRIM_trLogo_DrawBoopsiImage(struct Image *Image, struct impDraw *DrawMsg)
  150. {
  151.   struct    RastPort        * RPort           = DrawMsg->imp_RPort;
  152.   UWORD                     BackColor       = DrawMsg->imp_DrInfo->dri_Pens[BACKGROUNDPEN],
  153.                             TextColor       = DrawMsg->imp_DrInfo->dri_Pens[TEXTPEN];
  154.   WORD                      left            = Image->LeftEdge + DrawMsg->imp_Offset.X,
  155.                             top             = Image->TopEdge + DrawMsg->imp_Offset.Y,
  156.                             width           = Image->Width,
  157.                             height          = Image->Height,
  158.                             Arrow1Array[ARROWLENGTH*2] = {22,6, 30,2, 26,10, 22,6},
  159.                             Arrow2Array[ARROWLENGTH*2] = {34,18, 42,14, 38,22, 34,18},
  160.                             Arrow3Array[ARROWLENGTH*2] = {46,30, 54,26, 50,34, 46,30},
  161.                             LanceArray[LANCELENGTH*2] = {2,54, 36,20},
  162.                             CurveArray[CURVELENGTH*2] = {24,8, 22,10, 20,14, 19,18, 18,22, 19,26, 20,30, 22,34, 26,36, 30,37, 34,38, 38,37, 42,36, 46,34, 48,32};
  163.  
  164.   // Background
  165.   SetAfPt(RPort, NULL, -1);
  166.   SetAPen(RPort, BackColor);
  167.   SetDrMd(RPort, JAM1);
  168.   RectFill(RPort, left, top, left+width-1, top+height-1);
  169.  
  170.   // Adjust size (->square)
  171.   if(width>height)
  172.   {
  173.     left+=((width-height)/2);
  174.     width=height;
  175.   }
  176.   else if(width<height)
  177.   {
  178.     top+=((height-width)/2);
  179.     height=width;
  180.   }
  181.  
  182.   // Logo
  183.   SetAPen(RPort, TextColor);
  184.   TR_ScaledPolyDraw(RPort,ARROWLENGTH,Arrow1Array,56,56,width,height,left,top);
  185.   TR_ScaledPolyDraw(RPort,ARROWLENGTH,Arrow2Array,56,56,width,height,left,top);
  186.   TR_ScaledPolyDraw(RPort,ARROWLENGTH,Arrow3Array,56,56,width,height,left,top);
  187.   TR_ScaledPolyDraw(RPort,LANCELENGTH,LanceArray,56,56,width,height,left,top);
  188.   TR_ScaledPolyDraw(RPort,CURVELENGTH,CurveArray,56,56,width,height,left,top);
  189.  
  190.   return(TRUE);
  191. }
  192.  
  193.  
  194. ULONG    __asm TRIM_trLogo_DispatchBoopsiImage(register __a0 struct IClass *Class, register __a2 Object *Object, register __a1 Msg ObjMsg)
  195. {
  196.   ULONG retval;
  197.   struct Hook *hook=(struct Hook *)Class;
  198.   ULONG tempa4=__builtin_getreg(12);
  199.   __builtin_putreg(12,(ULONG)hook->h_Data);
  200.  
  201.   if(ObjMsg->MethodID==IM_DRAW) retval=TRIM_trLogo_DrawBoopsiImage((struct Image *)Object, (struct impDraw *)ObjMsg);
  202.   else retval=DoSuperMethodA(Class, Object, ObjMsg);
  203.  
  204.   __builtin_putreg(12,tempa4);
  205.   return retval;
  206. }
  207.  
  208.  
  209. BOOL __regargs TRIM_trLogo_Init(VOID)
  210. {
  211.   if((TRIM_trLogo = MakeClass(NULL, IMAGECLASS, NULL, 0, 0)))
  212.   {
  213.     TRIM_trLogo->cl_Dispatcher.h_Entry = (HOOKFUNC)TRIM_trLogo_DispatchBoopsiImage;
  214.     TRIM_trLogo->cl_Dispatcher.h_Data  = (void *) __builtin_getreg(12);
  215.   }
  216.   return (BOOL)TRIM_trLogo;
  217. }
  218.  
  219.  
  220. VOID __regargs TRIM_trLogo_Free(VOID)
  221. {
  222.   if(TRIM_trLogo) FreeClass(TRIM_trLogo);
  223. }
  224.